<template>
	<view class="bill-detail-page">
		<detail-head url="../bill/bill" type="mine"></detail-head>
		<view class="content">
			<view class="info">
				<!-- <view class="time">
					<text>剩余购买时间</text>
					<uni-countdown :show-day="false" color="#FFBD47" :second="time"></uni-countdown>
				</view> -->
				<view class="title">
					<text v-if="payStatus === 'PAYMENTS'">支付中</text>
					<text v-if="payStatus === 'CANCEL'">支付取消</text>
					<text v-if="payStatus === 'SUCCESS'">支付成功</text>
					<text v-if="payStatus === 'FAIL'">支付失败</text>
				</view>
				<view class="prod">
					<image :src="detail.activityProductVO ?detail.activityProductVO.subPctureUrl: ''" mode="aspectFit">
					</image>
					<view class="detail">
						<view class="name">{{detail.activityProductVO?detail.activityProductVO.name:''}}</view>
						<view class="item">
							<view class="label">金额</view>
							<view class="value">￥{{detail.tradeAmount}}</view>
						</view>
						<view class="item">
							<view class="label">编号</view>
							<view class="value">{{detail.orderCode}}</view>
						</view>
					</view>
				</view>
				<view class="subtitle">订单说明</view>
				<view class="desc">1.一个用户同时允许存在一笔待支付订单</view>
				<view class="desc">2. 若您短时间末支付违约订羊过多,将会被禁止购买一段时间</view>
				<button class="sale-btn" type="default" @click="onCancelPay" v-show="payStatus === 'PAYMENTS'"
					:loading="btnLoading">{{btnLoading ? '' : '取消订单'}}</button>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		cancelPay,
		getPayDetails,
	} from '../../request/bill.js'
	export default {
		data() {
			return {
				// 详情
				detail: {},
				// 状态
				payStatus: '',
				// 价格
				time: 0,
				// 按钮状态
				btnLoading: false,
				// 总数据
				total: {
					afterTaxAmount: 0,
					procedureFee: 0,
					copyrightTax: 0,
					copyrightTax: 0,
					procedureFee: 0
				}

			}
		},
		onLoad(option) {
			this.payStatus = option.type
			this.getBillDetails(option.id)
		},
		methods: {

			// 加载详情
			async getBillDetails(id) {
				uni.showLoading({
					title: '加载中...'
				})
				try {
					let {
						code,
						message,
						data
					} = await getPayDetails(id)
					if (code === 200) {
						this.detail = data
						this.time = (parseInt((new Date((data.createTime).replace(/-/g, '/')).getTime() / 1000 +
							300)) - parseInt(new Date().getTime() / 1000))
						// this.time = 10
						console.log(this.time)
					} else {
						uni.showToast({
							title: message,
							icon: 'error'
						})
					}
				} catch (err) {
					console.log(err)
					uni.showToast({
						title: '服务繁忙',
						icon: 'error'
					})
				}
				uni.hideLoading()
			},
			// 取消订单
			async onCancelPay() {
				this.btnLoading = true
				try {
					let {
						code,
						message,
						data
					} = await cancelPay(this.detail.id)
					if (code === 200) {
						uni.showToast({
							title: '订单取消成功',
							icon: 'success'
						})
						uni.navigateTo({
							url: '../bill/bill',
							animationType: 'pop-in',
							animationDuration: 200
						})
					} else {
						uni.showToast({
							title: message,
							icon: 'none'
						})
					}
				} catch (err) {
					console.log(err)
					uni.showToast({
						title: '服务繁忙',
						icon: 'error'
					})
				}
				this.btnLoading = false
			},
		}
	}
</script>

<style lang="scss" scoped>
	.bill-detail-page {
		width: 100%;
		min-height: 100vh;
		background: $login-background-url no-repeat;
		background-size: 100% 100%;
		background-position: 0 -60rpx;
	}

	.content {
		width: 100%;
		padding: 0 20rpx;
		margin-top: 80rpx;
		margin-bottom: 80rpx;
	}

	.info {
		height: 1152rpx;
		width: 100%;
		padding: 180rpx 40rpx 0 40rpx;
		background: $sale-back-url no-repeat;
		background-size: 100% 100%;
		background-position: 0 0;
		position: relative;

		.time {
			width: 100%;
			height: 64rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: absolute;
			top: 20rpx;
			left: 50%;
			transform: translateX(-50%);

			text {
				color: #979797;
				margin-right: 20rpx;
			}
		}

		.title {
			line-height: 64rpx;
			text-align: center;
			font-size: 14px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFBD47;
		}

		.subtitle {
			font-size: 18px;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #9D9D9D;
		}

		.prod {
			width: 100%;
			height: 240rpx;
			// padding: 20rpx 0 20rpx 10rpx;
			margin: 40rpx 0;
			display: flex;
			align-items: center;
			justify-content: space-between;

			border: 1px solid #979797;
			border-left: none;
			border-right: none;

			image {
				width: 190rpx;
				height: 190rpx;
				margin-right: 20rpx;
			}

			.detail {
				flex: 1;
				height: 200rpx;
				padding: 10rpx 0;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: space-between;

				.name {
					width: 100%;
					text-align: left;
					font-size: 16px;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #9D9D9D;
				}

				.item {
					width: 100%;
					height: 48rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.label {
						width: 50rpx;
						font-size: 24rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #979797;
					}

					.value {
						flex: 1;
						text-align: right;
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #979797;
					}
				}
			}
		}

		.price {
			width: 100%;
			height: 68rpx;
			margin: 20rpx 0;
			border-radius: 16rpx;
			background: linear-gradient(#383838, #050505);
			display: flex;

			input {
				width: 100%;
				height: 100%;
				text-indent: 20rpx;
				color: #979797;
			}

			.icon {
				width: 60rpx;
				height: 100%;
				text-align: center;
				line-height: 64rpx;
				color: #FFBD47;
			}
		}

		.desc {
			margin: 40rpx 0;
			font-size: 12px;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #979797;
		}

		.sale-btn {
			flex: 1;
			margin-top: 80rpx;
			color: #FFBD47;
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: #121212;
			box-shadow: -10px -10px 20px 0px rgba(39, 39, 39, 0.54), 10px 10px 20px 0px rgba(0, 0, 0, 0.83);
			border-radius: 22px;
			border: 1px solid #FFBD47;
		}
	}
</style>
